<template>
  <div class="playlist">
    <h4
      class="title"
      v-if="title">
      {{ title }}
    </h4>
    <div class="content">
      <div
        v-for="item in playlists"
        :key="item.id"
        class="list">
        <div
          @click="toPlayList(item)"
          class="mask">
          <span class="iconfont">&#xea82;</span>
        </div>
        <el-image
          fit="cover"
          :src="item.image"
          lazy />
        <span class="name">{{ item.name }}</span>
        <span class="playcount iconfont"
          >&#xe6b1; {{ (+item.playCount / 10000).toFixed(1) }}万</span
        >
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { Playlist } from '../model';
import { useRouter } from 'vue-router';
import { getTheme } from '../utils/util';
import { inject } from 'vue';
//设置主题
const boxShadow = getTheme().get('shadow');
const color = getTheme().get('fontColor');
const router = useRouter();
//设置隐藏滚动条
const hideScroll = inject('hideScroll') as Function;

defineProps<{
  title?: string;
  playlists: Playlist[];
}>();
//点击歌单，前往歌单详情页
const toPlayList = (list: Playlist) => {
  hideScroll();
  router.push({
    name: 'playlist',
    query: {
      id: list.id,
    },
  });
};
</script>

<style lang="less" scoped>
@font-color: v-bind(color);
@shadow: v-bind(boxShadow);
@font-color-gray: #7b7b7b;
@font-color-green: #1ed2a9;
@font-color-white: #ffffff;
@common-width: 230px;

.playlist {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
  .title {
    font-weight: 520;
    font-size: 20px;
    letter-spacing: 1px;
    width: 81vw;
    color: @font-color;
    padding-left: 9px;
  }
  .content {
    width: 81vw;
    display: flex;
    flex-wrap: wrap;

    .list {
      display: flex;
      flex-direction: column;
      margin: 20px 9px 0;
      position: relative;
      cursor: pointer;
      .mask {
        width: @common-width;
        height: @common-width;
        background-color: rgba(0, 0, 0, 0.5);
        position: absolute;
        top: 0;
        border-radius: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: rgba(255, 255, 255, 0.4);
        opacity: 0;
        transition: 0.5s;
        z-index: 10;
        span {
          font-size: 50px;
          transition: 0.4;
          &:hover {
            color: @font-color-green;
          }
        }
      }

      &:hover .el-image {
        transform: translateY(-5px);
      }
      &:hover .mask {
        opacity: 1;
        transform: translateY(-5px);
      }
      &:hover .playcount {
        opacity: 0;
      }
      transition: 0.5s;
      .el-image {
        width: @common-width;
        height: @common-width;
        border-radius: 10px;
        box-shadow: @shadow;
        transition: 0.5s;
      }
      .playcount {
        font-size: 12px;
        display: inline-block;
        text-align: center;
        line-height: 20px;
        height: 20px;
        min-width: 70px;
        padding: 0 5px;
        color: @font-color-white;
        background-color: rgba(0, 0, 0, 0.8);
        border-radius: 10px;
        position: absolute;
        top: 200px;
        right: 12px;
      }
      .name {
        width: @common-width;
        white-space: wrap;
        font-size: 12px;
        display: inline-block;
        margin-top: 5px;
        color: @font-color;
      }
    }
  }
}
</style>
